package com.spontaneappnew.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.spontaneappnew.activities.ImageGalleryActivity;

public class PlacePicturesAdapter extends PagerAdapter {
	Context context;
	private ArrayList<ImageView> imageFiles;
	private boolean onClickAvailable;

	public PlacePicturesAdapter(Context context, ArrayList<ImageView> images, boolean withOnClick){
		this.context=context;
		Log.d("TAG",images.size()+"");
		this.imageFiles=images;
		this.onClickAvailable = withOnClick;
	}
	
	@Override
	public int getCount() {
		return imageFiles.size();
	}
	 
	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == ((ImageView) object);
	}
	 
	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		final int pos = position;
 		((ViewPager) container).addView(imageFiles.get(position), 0);
 		if (onClickAvailable){
 			imageFiles.get(position).setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Intent intent = new Intent(context, ImageGalleryActivity.class);
					intent.putExtra("CurrentImage", pos);
					context.startActivity(intent);
				}
			});
 			
 		}
		return imageFiles.get(position);
	}
	 
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		((ViewPager) container).removeView((ImageView) object);
	}
}